{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-08-02 19:40:28.819\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m48\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-08-02 19:40:28,868\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-08-02 19:40:28,881\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The image features a colorful illustration of multiple cats with various expressions and poses, all set against a blue background. The cats appear to be a mix of different breeds and colors, primarily showcasing orange, white, and black fur. The artwork has a playful and whimsical style.\n"
     ]
    }
   ],
   "source": [
    "import byzerllm\n",
    "import json\n",
    "import base64\n",
    "\n",
    "llm = byzerllm.ByzerLLM.from_default_model(\"gpt4o_mini_chat\")\n",
    "\n",
    "image_data = base64.b64encode(open(\"../images/cat2.png\", \"rb\").read()).decode()\n",
    "\n",
    "v = llm.chat_oai(\n",
    "    conversations=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": json.dumps(\n",
    "                [\n",
    "                    {\"image\": f\"data:image/png;base64,{image_data}\"},\n",
    "                    {\"text\": \"what in this image?\"},\n",
    "                ],\n",
    "                ensure_ascii=False,\n",
    "            ),\n",
    "        }\n",
    "    ]\n",
    ")\n",
    "print(v[0].output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-10-19 22:58:00.625\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m48\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-10-19 22:58:00,682\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-10-19 22:58:00,703\tINFO worker.py:1740 -- Connected to Ray cluster. View the dashboard at \u001b[1m\u001b[32m127.0.0.1:8265 \u001b[39m\u001b[22m\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The image is a colorful illustrationThe image is a colorful illustration ofThe image is a colorful illustration of a largeThe image is a colorful illustration of a large groupThe image is a colorful illustration of a large group ofThe image is a colorful illustration of a large group of catsThe image is a colorful illustration of a large group of cats stackedThe image is a colorful illustration of a large group of cats stacked onThe image is a colorful illustration of a large group of cats stacked on topThe image is a colorful illustration of a large group of cats stacked on top ofThe image is a colorful illustration of a large group of cats stacked on top of eachThe image is a colorful illustration of a large group of cats stacked on top of each otherThe image is a colorful illustration of a large group of cats stacked on top of each other.The image is a colorful illustration of a large group of cats stacked on top of each other. TheThe image is a colorful illustration of a large group of cats stacked on top of each other. The catsThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats areThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depictedThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted inThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in variousThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colorsThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors andThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patternsThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns,The image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, includingThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orangeThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange,The image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, whiteThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white,The image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, andThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and blackThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black.The image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. TheThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The backgroundThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background isThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is aThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solidThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blueThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue colorThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color.The image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. TheThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustrationThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration hasThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has aThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsicalThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical andThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playfulThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful styleThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style,The image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, withThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with theThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the catsThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the cats arrangedThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the cats arranged inThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the cats arranged in aThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the cats arranged in a somewhatThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the cats arranged in a somewhat organizedThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the cats arranged in a somewhat organized butThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the cats arranged in a somewhat organized but playfulThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the cats arranged in a somewhat organized but playful mannerThe image is a colorful illustration of a large group of cats stacked on top of each other. The cats are depicted in various colors and patterns, including orange, white, and black. The background is a solid blue color. The illustration has a whimsical and playful style, with the cats arranged in a somewhat organized but playful manner."
     ]
    }
   ],
   "source": [
    "import byzerllm\n",
    "import json\n",
    "import base64\n",
    "\n",
    "llm = byzerllm.ByzerLLM.from_default_model(\"qwen_vl\")\n",
    "\n",
    "image_data = base64.b64encode(open(\"../images/cat2.png\", \"rb\").read()).decode()\n",
    "\n",
    "v = llm.stream_chat_oai(\n",
    "    conversations=[\n",
    "        {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": json.dumps(\n",
    "                [\n",
    "                    {\"image\": f\"data:image/png;base64,{image_data}\"},\n",
    "                    {\"text\": \"what in this image?\"},\n",
    "                ],\n",
    "                ensure_ascii=False,\n",
    "            ),\n",
    "        }\n",
    "    ],delta_mode=True\n",
    ")\n",
    "for item in v:\n",
    "    print(item[0],end=\"\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "byzerllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
